package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OldMan;
import com.ruoyi.system.service.IOldManService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老人信息Controller
 * 
 * @author 王帅
 * @date 2024-08-24
 */
@Controller
@RequestMapping("/system/man")
public class OldManController extends BaseController
{
    private String prefix = "system/man";

    @Autowired
    private IOldManService oldManService;


    @GetMapping()
    public String man()
    {
        return prefix + "/man";
    }

    /**
     * 查询老人信息列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OldMan oldMan)
    {
        startPage();
        List<OldMan> list = oldManService.selectOldManList(oldMan);
        return getDataTable(list);
    }

    /**
     * 导出老人信息列表
     */

    @Log(title = "老人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OldMan oldMan)
    {
        List<OldMan> list = oldManService.selectOldManList(oldMan);
        ExcelUtil<OldMan> util = new ExcelUtil<OldMan>(OldMan.class);
        return util.exportExcel(list, "老人信息数据");
    }

    /**
     * 新增老人信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存老人信息
     */

    @Log(title = "老人信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OldMan oldMan)
    {
        return toAjax(oldManService.insertOldMan(oldMan));
    }

    /**
     * 修改老人信息
     */

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OldMan oldMan = oldManService.selectOldManById(id);
        mmap.put("oldMan", oldMan);
        return prefix + "/edit";
    }

    /**
     * 修改保存老人信息
     */

    @Log(title = "老人信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OldMan oldMan)
    {
        return toAjax(oldManService.updateOldMan(oldMan));
    }

    /**
     * 删除老人信息
     */

    @Log(title = "老人信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oldManService.deleteOldManByIds(ids));
    }
}
